package edu.tongji.structureplayer.structure
{
    public class PiecewiseFunction extends BaseStructure
    {
        private var _xPos:Array;
        private var _yPos:Array;
        
        public function PiecewiseFunction(name:String, xPos:Array, yPos:Array)
        {
            super(name);
            _xPos = xPos;
            _yPos = yPos;
        }
        
        public function overlap(xPos:Array, yPos:Array):Boolean
        {
            if (null==xPos || null==yPos || null==_xPos || null==_yPos)
                return false;
            if (xPos.length!=_xPos.length || yPos.length!=_yPos.length)
                return false;
            
            for (var i:uint=0; i<xPos.length; i++)
                if (_xPos[i]!=xPos[i])return false;
            
            for (var j:uint=0; j<yPos.length; j++)
                if (_yPos[j]!=yPos[j])return false;
            
            return true;
        }

        public function get yPos():Array
        {
            return _yPos;
        }

        public function set yPos(value:Array):void
        {
            _yPos = value;
        }

        public function get xPos():Array
        {
            return _xPos;
        }

        public function set xPos(value:Array):void
        {
            _xPos = value;
        }
        
        public function debugPrint():void
        {
            var points:String = "" ;
            if (null==_xPos || _xPos.length==0)
                points = "";
            else {
                for (var i:uint=0; i+1<_xPos.length; i++)
                {
                    points += (_xPos[i] + ", ");
                    points += (_yPos[i] + ", ");
                }
                points += (_xPos[_xPos.length-1] + ", ");
                points += _yPos[_yPos.length-1];
            }
                
            trace ("PiecewiseFunction " + name + "(" + points + ")");
        }

    }
}